/**
 * 
 */
package com.ruanyun.tio.start;

import com.ruanyun.tio.net.server.IpStatListener;
import com.ruanyun.tio.net.server.ServerAioHandler;
import com.ruanyun.tio.net.server.ServerAioListener;
import org.springframework.stereotype.Component;
import org.tio.server.ServerTioConfig;
import org.tio.server.TioServer;

import javax.annotation.PostConstruct;
import java.io.IOException;

/**
 * @author tanyaowu
 *
 */
@Component
public class ServerStarter {

	//一组连接共用的上下文对象
	public static ServerTioConfig serverTioConfig = new ServerTioConfig(ServerConfig.PROTOCOL_NAME, ServerAioHandler.me, ServerAioListener.me);

	//tioServer对象
	public static TioServer tioServer = new TioServer(serverTioConfig);


	/**
	 *
	 * @throws IOException
	 */
	@PostConstruct
	public static void start() throws IOException {
		serverTioConfig.setHeartbeatTimeout(ServerConfig.HEARTBEAT_TIMEOUT);//设置心跳超时时间
		//设置ip数据监控
		serverTioConfig.ipStats.addDurations(ServerConfig.IpStatDuration.IPSTAT_DURATIONS);
		serverTioConfig.setIpStatListener(IpStatListener.me);
		tioServer.start(ServerConfig.SERVER_IP, ServerConfig.SERVER_PORT);
	}
	
	public static void main(String[] args) throws IOException {
		start();
	}

}
